package com.okami.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.Lifecycle;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import javax.annotation.PostConstruct;
import javax.annotation.Priority;
import javax.annotation.Resource;
import javax.servlet.ServletContext;
import java.beans.ConstructorProperties;
import java.util.Optional;

/**
 * @author: TanJingyu
 * @create: 2021-03-24 22:41
 **/
@ComponentScan
@Priority(1)
public class MainClass {
    @Bean
//    @ConstructorProperties()
    public static void main(String[] args) {
//        BeanFactory beanFactory = new DefaultListableBeanFactory();
//        ApplicationContext applicationContext = null;
//        BeanDefinition beanDefinition = null;

//        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
//
//        AnnotationConfigApplicationContext container1 = new AnnotationConfigApplicationContext(DDD.class, TTT.class, TTT.class);
//        AnnotationConfigApplicationContext container1 = new AnnotationConfigApplicationContext(DDD.class);

        AnnotationConfigApplicationContext container1 = new AnnotationConfigApplicationContext(MyConfig.class);
        container1.getBeanFactory();
    }

    public static class DDD {

    }

    public static class TTT {
        @Autowired
        private DDD ddd1;
        private DDD ddd2;

        public void ddd2(DDD ddd2) {
            this.ddd2 = ddd2;
        }
    }

    @Configuration(proxyBeanMethods = false)
    @ComponentScan(basePackages = "com.okami.spring")
    static class MyConfig extends MyConfigFather{

    }

    public static class MyConfigFather {
        @Bean
        DDD ddd() {
            return new DDD();
        }

        @Bean
        TTT ttt() {
            TTT ttt = new TTT();
            ttt.ddd2(ddd());
            return ttt;
        }
    }

}
